package org.example.newcoder_summer.Controller;

import lombok.extern.slf4j.Slf4j;
import org.example.newcoder_summer.pojo.Result;
import org.example.newcoder_summer.pojo.Todo;
import org.example.newcoder_summer.service.TodoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
public class TodoController {

    @Autowired
    private TodoService todoService;
    //增加todo任务
    @PostMapping("/home")
    public Result add(@RequestBody Todo todo){
        todoService.save(todo);
        return Result.success();
    }

    //查询每日任务清单
    @GetMapping("/home")
    public Result select(int userId, LocalDateTime createTime) {
        List<Todo> todoList = todoService.GetTodoList(userId, createTime);
        return Result.success(todoList);
    }

    //删除任务
    @DeleteMapping("/home")
    public Result delete(List<Integer> ids) {
        log.info("批量删除");
        todoService.delete(ids);
        return Result.success();
    }

    //更改任务
    @PostMapping("/home")
    public Result update(@RequestBody Todo todo){
        todoService.update(todo);
        return Result.success();
    }
}
